#include "stdafx.h"
#include "Player.h"
#include "MouseSource.h"


Player::Player(Evironment* e)
	:CoreBase(e),currentReceiver(0)
{
	MouseSource::getInstance()->SetMouseBoundary(0,e->GetMapSize().height-1,0,e->GetMapSize().width-1);
	MouseSource::getInstance()->add(this);
}
using Core::Position;
void Player::OnMouseEvent (SourceType& mouse)
{
	int x=mouse.x;
	int y=mouse.y;
	Core::SimpleMap::MapInfo info=e->GetInfo(Position(x,y));
	if(mouse.left)
	{
		if(info.element)
		{
			this->currentReceiver=info.element;
		}
		else
			this->currentReceiver=0;
	}
	else if(mouse.right)
	{
		if(currentReceiver)
		{
			ParamList* p=new ParamList();
			Core::Position t=e->GetGridPosition(Position(x,y));
			p->Add("des",Param(Core::POSITION,new Core::Position(t.x,t.y)));
			currentReceiver->ReceiveCommand(Core::Command("move",p));
		}
	}
	
}